package com.demo.singleton;

/**
 * @Author: shubin_yao
 * @Date: 2022/05/10/21:37
 * @Description: 懒汉模式-双重锁检测: 线程安全
 * <p>
 * 优点: ⽅法级锁的优化，减少了部分获取实例的耗时
 */
public class Singleton_05 {

    private static Singleton_05 instance;

    private Singleton_05() {
        System.out.println("=======懒汉模式-双重锁检测: 线程安全 ,构造方法Singleton_05");
    }

    public static Singleton_05 getInstance() {
        if (instance != null) return instance;
        synchronized (Singleton_05.class) {
            if (instance == null) {
                instance = new Singleton_05();
            }
        }
        return instance;
    }

}
